//
//  CLPersonInfoControllerT.m
//  CareLink
//
//  Created by 赵玉忠 on 16/8/22.
//  Copyright © 2016年 Seven Team. All rights reserved.
//

#import "CLPersonInfoControllerT.h"

// contain this header
#import "UIView+TYAlertView.h"
// if you want blur efffect contain this
#import "TYAlertController+BlurEffects.h"

#import "SettingModelView.h"
#import "ShareView.h"

#import "PersonTableViewCell.h"

#import "CLZoomPickerView.h"

#import "PersonMassageModel.h"

@interface CLPersonInfoControllerT () <UITableViewDelegate, UITableViewDataSource, CLZoomPickerViewDelegate, CLZoomPickerViewDataSource, UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@property (weak, nonatomic) UIImageView* iconImageView;

//名字

@property (weak, nonatomic) UIButton* userNameBtn;

@property (weak, nonatomic) UIButton* identifierBtn;

@property (weak, nonatomic) UIButton* phoneNumButton;

@property (strong, nonatomic) NSArray* dataArray;

//滚动器数组
@property (nonatomic, strong) NSArray* OneArray;
//@property (nonatomic, strong) NSArray *weightArray;
//@property (nonatomic, strong) NSArray *provinceArray;
//滚动器视图
@property (nonatomic, strong) CLZoomPickerView* pickerView;

@property (nonatomic, strong) PersonMassageModel* model;

@property (nonatomic, strong) UILabel* changeLabel;

@property (nonatomic, strong) NSMutableArray* MMDArray;

@end

@implementation CLPersonInfoControllerT
#pragma mark - 懒加载labelArray
- (NSMutableArray*)MMDArray
{
    if (_MMDArray == nil) {
        _MMDArray = [[NSMutableArray alloc] init];
    }
    return _MMDArray;
}
- (void)setNavabar
{
    self.navigationItem.title = @"个人信息修改";
    UIBarButtonItem* finishiItem = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(finish)];

    //    UIButton*rightButton = [[UIButton alloc]initWithFrame:CGRectMake(0,0,30,30)];
    //    [rightButton setTitle:@"完成" forState:UIControlStateNormal];

    //    UIBarButtonItem *finishiItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:@selector(methodtocall:) ];
    self.navigationItem.rightBarButtonItem = finishiItem;
}
#pragma mark - 监听导航条完成按钮
- (void)finish
{
    NSLog(@"点击了完成按钮,保存数据");
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad
{
#pragma mark - 设置导航条上的按钮及文字
    [self setNavabar];
    //创建身高数据
    NSMutableArray* heightArray = [NSMutableArray array];
    for (int i = 100; i < 250; i++) {
        NSString* heightStr = [NSString stringWithFormat:@"%d", i];
        [heightArray addObject:heightStr];
    }
    [self.MMDArray addObject:heightArray];

    //创建体重数据
    NSMutableArray* weightArray = [NSMutableArray array];
    for (int i = 25; i < 100; i++) {
        NSString* heightStr = [NSString stringWithFormat:@"%dkg", i];
        [weightArray addObject:heightStr];
    }
    [self.MMDArray addObject:weightArray];
    //创建体重数据
    NSMutableArray* provinceArray = [NSMutableArray array];
    NSString* path = [[NSBundle mainBundle] pathForResource:@"cityList.plist" ofType:nil];
    NSArray* dictArray = [NSArray arrayWithContentsOfFile:path];
    for (NSDictionary* dict in dictArray) {
        NSString* str = [dict objectForKey:@"name"];
        [provinceArray addObject:str];
    }

    //
    [self.MMDArray addObject:provinceArray];

    [self loadData];
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];

#pragma mark - 头像添加轻触手势
    //头像视图
    UIImageView* imageView = [[UIImageView alloc] init];
    self.iconImageView = imageView;
    imageView.userInteractionEnabled = YES;
    //添加轻触手势
    UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)];
    //2.添加
    [imageView addGestureRecognizer:tap];

    self.iconImageView = imageView;
    imageView.image = [UIImage imageNamed:@"patient_defaultphoto_male"];
    //    [imageView sizeToFit];
    imageView.contentMode = UIViewContentModeScaleToFill;
    
    //设置圆角
    self.iconImageView.layer.cornerRadius = 45;
    self.iconImageView.layer.masksToBounds = YES;

    [self.view addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker* make) {
        make.left.offset(30);
        make.top.offset(10);
        make.width.height.offset(90);
    }];
    
    //图标
    UIImageView* imageViewName = [[UIImageView alloc] init];
    imageViewName.image = [UIImage imageNamed:@"0@3x-1"];
    //    [imageView sizeToFit];
    imageViewName.contentMode = UIViewContentModeScaleToFill;
    [self.view addSubview:imageViewName];
    [imageViewName mas_makeConstraints:^(MASConstraintMaker* make) {
        make.left.equalTo(imageView.mas_right).offset(10);
        make.top.equalTo(imageView.mas_top).offset(2);
        make.width.height.offset(22);
    }];

    //图标2
    UIImageView* imageViewIdentifier = [[UIImageView alloc] init];
    imageViewIdentifier.image = [UIImage imageNamed:@"id"];
    //    [imageView sizeToFit];
    imageViewIdentifier.contentMode = UIViewContentModeScaleToFill;
    [self.view addSubview:imageViewIdentifier];
    [imageViewIdentifier mas_makeConstraints:^(MASConstraintMaker* make) {
        make.left.equalTo(imageViewName.mas_left);
        make.centerY.equalTo(imageView.mas_centerY);
        //        make.top.equalTo(imageViewName.mas_bottom).offset(5);
        make.width.height.offset(22);
    }];

    //图标3
    UIImageView* imageViewPhone = [[UIImageView alloc] init];
    imageViewPhone.image = [UIImage imageNamed:@"login_phone"];
    //    [imageView sizeToFit];
    imageViewPhone.contentMode = UIViewContentModeScaleToFill;
    [self.view addSubview:imageViewPhone];
    [imageViewPhone mas_makeConstraints:^(MASConstraintMaker* make) {
        make.left.equalTo(imageViewIdentifier.mas_left);
        make.bottom.equalTo(imageView.mas_bottom).offset(-5);
        make.width.height.offset(22);
    }];

    //按钮1
    UIButton* btnName = [[UIButton alloc] init];
    btnName.tag = 0;
    //    btnName.backgroundColor = [UIColor redColor];

    //读取数据.用户名
    NSString* str = [[NSUserDefaults standardUserDefaults] objectForKey:KsmallName];
    if (str ==nil) {
        [btnName setTitle:@"871781508@qq.com" forState:UIControlStateNormal];
    }else{
        [btnName setTitle:str forState:UIControlStateNormal];
    }
    

    btnName.titleLabel.font = [UIFont systemFontOfSize:15];
    [btnName setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btnName.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    //    [btnName.titleLabel sizeToFit];
    [self.view addSubview:btnName];
    [btnName mas_makeConstraints:^(MASConstraintMaker* make) {
        make.left.equalTo(imageViewName.mas_right).offset(5);
        make.top.equalTo(imageViewName.mas_top);
        make.height.equalTo(imageViewName.mas_height);
        make.right.offset(-5);
    }];

    [btnName addTarget:self action:@selector(changeName:) forControlEvents:UIControlEventTouchUpInside];
    self.userNameBtn = btnName;

    //按钮2
    UIButton* btnIdetifier = [[UIButton alloc] init];
    btnIdetifier.titleLabel.font = [UIFont systemFontOfSize:15];
    btnIdetifier.tag = 1;
    //    btnName.backgroundColor = [UIColor redColor];

    //读取数据.身份证
    //    NSString *str1 = [[NSUserDefaults standardUserDefaults] objectForKey:KUserName];
    //    [btnIdetifier setTitle:str1 forState:UIControlStateNormal];

    NSString* str1 = [[NSUserDefaults standardUserDefaults] objectForKey:Kidetifier];
    if (str1 ==nil) {
        [btnIdetifier setTitle:@"130725188234282746" forState:UIControlStateNormal];
    }else{
        [btnIdetifier setTitle:str1 forState:UIControlStateNormal];
    }

    [btnIdetifier setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btnIdetifier.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    //    [btnName.titleLabel sizeToFit];
    [self.view addSubview:btnIdetifier];
    [btnIdetifier mas_makeConstraints:^(MASConstraintMaker* make) {
        make.left.equalTo(imageViewIdentifier.mas_right).offset(5);
        make.top.equalTo(imageViewIdentifier.mas_top);
        make.height.equalTo(imageViewIdentifier.mas_height);
        make.right.equalTo(btnName.mas_right);
    }];

    [btnIdetifier addTarget:self action:@selector(changeName:) forControlEvents:UIControlEventTouchUpInside];
    self.identifierBtn = btnIdetifier;

    //按钮3
    UIButton* btnPhone = [[UIButton alloc] init];
    btnPhone.titleLabel.font = [UIFont systemFontOfSize:15];
    btnPhone.tag = 2;
    //    btnName.backgroundColor = [UIColor redColor];

    //读取数据.用户名
    NSString* str3 = [[NSUserDefaults standardUserDefaults] objectForKey:KUserName];
    if (str3 ==nil) {
        [btnPhone setTitle:@"18301166921" forState:UIControlStateNormal];
    }else{
        [btnPhone setTitle:str3 forState:UIControlStateNormal];
    }


    //    [btnPhone setTitle:@"13986230753" forState:UIControlStateNormal];
    [btnPhone setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    btnPhone.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    //    [btnName.titleLabel sizeToFit];
    [self.view addSubview:btnPhone];
    [btnPhone mas_makeConstraints:^(MASConstraintMaker* make) {
        make.left.equalTo(imageViewPhone.mas_right).offset(5);
        make.top.equalTo(imageViewPhone.mas_top);
        make.height.equalTo(imageViewPhone.mas_height);
        make.right.equalTo(btnIdetifier.mas_right);
    }];

    [btnPhone addTarget:self action:@selector(changeName:) forControlEvents:UIControlEventTouchUpInside];
    self.phoneNumButton = btnPhone;

    //增加tableView
    UITableView* tableView = [[UITableView alloc] init];
    [self.view addSubview:tableView];
    [tableView mas_makeConstraints:^(MASConstraintMaker* make) {
        make.left.right.offset(0);
        make.top.equalTo(imageView.mas_bottom).offset(30);
        make.height.offset(150);
    }];
    tableView.delegate = self;
    tableView.dataSource = self;
    [tableView registerClass:[PersonTableViewCell class] forCellReuseIdentifier:@"cellid"];
}
#pragma mark - 打开本地相册的方法
- (void)pickPhoto
{
    UIImagePickerController* picker = [[UIImagePickerController alloc] init];
    //打开相册的方式
    picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    //设置代理
    picker.delegate = self;
    //设置图片可以编辑
    picker.allowsEditing = YES;

    [self presentViewController:picker animated:YES completion:nil];
}

#pragma mark -更换头像按钮
- (void)tap
{
    NSLog(@"点击了更换头像手势");
    TYAlertView* alertView = [TYAlertView alertViewWithTitle:@"更换头像" message:@"请选择操作!"];

    [alertView addAction:[TYAlertAction actionWithTitle:@"打开本地相册" style:TYAlertActionStyleDefault handler:^(TYAlertAction* action) {
                   NSLog(@"%@", action.title);
                   [self pickPhoto];
//        [self saveImage:<#(UIImage *)#>];
               }]];

    [alertView addAction:[TYAlertAction actionWithTitle:@"打开照相机" style:TYAlertActionStyleDefault handler:^(TYAlertAction* action) {
                   NSLog(@"%@", action.title);
                   NSLog(@"点击了打开照相机");
                   [self ClickControlAction];
               }]];

    //    [alertView addAction:[TYAlertAction actionWithTitle:@"删除" style:TYAlertActionStyleDestructive handler:^(TYAlertAction *action) {
    //        NSLog(@"%@",action.title);
    //    }]];
    [alertView addAction:[TYAlertAction actionWithTitle:@"取消" style:TYAlertActionStyleCancle handler:^(TYAlertAction* action) {
                   NSLog(@"%@", action.title);
               }]];

    TYAlertController* alertController = [TYAlertController alertControllerWithAlertView:alertView preferredStyle:TYAlertControllerStyleActionSheet];
    [self presentViewController:alertController animated:YES completion:nil];
}

#pragma mark - loadData
- (void)loadData
{
    //    NSURL *url = [[NSBundle mainBundle]URLForResource:@"PersonManager.plist" withExtension:nil];
    //    NSArray *array = [NSArray arrayWithContentsOfURL:url];
    //    NSMutableArray *marray = [NSMutableArray array];
    //    for (NSDictionary *dict in array) {
    //        ZFBLifeCycleModel *model = [ZFBLifeCycleModel modelWithDict:dict];
    //        [marray addObject:model];
    //    }
    NSArray* array = [NSArray objectListWithPlistName:@"PersonManager.plist" clsName:@"PersonMassageModel"];
    self.dataArray = array.copy;
}
#pragma mark - tableViewDataSouce
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
    PersonTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cellid" forIndexPath:indexPath];
    cell.contentView.backgroundColor = [UIColor colorWithHex:0xf5f5f5];
    PersonMassageModel* model = self.dataArray[indexPath.row];
    cell.model = model;
    //    [self.labelArray addObject:cell];
    return cell;
}

#pragma mark - 监听cell的点击,弹出滚动器
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
    //点击时立即取消背景
    [tableView deselectRowAtIndexPath:indexPath animated:NO];

    PersonTableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath];
    self.changeLabel = cell.dataLabel;

    //弹出修改视图
    CLZoomPickerView* pickerView = [CLZoomPickerView sharedPickerView];
    self.pickerView = pickerView;
    //    UIImageView *imageView = [[UIImageView alloc]init];
    //    imageView.image = [UIImage imageNamed:@"h1"];
    //    imageView.contentMode = UIViewContentModeScaleToFill;
    //    [pickerView addSubview:imageView];
    //    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.top.bottom.left.right.offset(0);
    //    }];
    self.model = self.dataArray[indexPath.row];
    [self.view addSubview:pickerView];
    pickerView.frame = CGRectMake(75 * 0.5, 367, 300, 300);

    //设置滚动器参数
    [self setPick:indexPath];
    //    self.changeLabel = self.labelArray[indexPath.row];
}
- (void)setPick:(NSIndexPath*)indexPath
{
    //    _heightArray = [NSArray arrayWithObjects:@"20min",@"30min",@"40min",@"50min",@"60min",@"70min",@"80min",@"90min",nil];
    NSArray* array = self.MMDArray[indexPath.row];
    _OneArray = array;

    self.pickerView.dataSource = self;
    self.pickerView.delegate = self;

    self.pickerView.topRowCount = 2;
    self.pickerView.bottomRowCount = 2;

    self.pickerView.selectedRow = 1;
    self.pickerView.rowHeight = 40;
    self.pickerView.selectedRowFont = [UIFont fontWithName:@"DIN Condensed" size:35];
    self.pickerView.textColor = [UIColor redColor];
    self.pickerView.unselectedRowScale = 0.5;

    //    PersonMassageModel *model = self.dataArray[indexPath.row];
    //    model.data =
    //    self.viewHeightLabel.text = [NSString stringWithFormat:@"高度：%.2f", self.pickerView.fitHeight];
}
#pragma mark - CLZoomPickerView 代理

// CLZoomPickerView 代理，当前项改变后调用此方法
- (void)pickerView:(CLZoomPickerView*)pickerView changedIndex:(NSUInteger)indexPath
{
    //    self.displayTextLabel.text = _heightArray[indexPath];
    NSString* str = _OneArray[indexPath];
    self.changeLabel.text = str;

    //    self.model.data = _heightArray[indexPath];

    //    [self.view layoutIfNeeded];
}

// CLZoomPickerView 代理，返回数据行数
- (NSInteger)pickerView:(CLZoomPickerView*)pickerView
{
    return _OneArray.count;
}

// CLZoomPickerView 代理，返回指定行显示的字符串
- (NSString*)pickerView:(CLZoomPickerView*)pickerView titleForRow:(NSUInteger)indexPath
{
    return _OneArray[indexPath];
}

#pragma mark - 改账户名
- (void)changeName:(UIButton*)sender
{
    TYAlertView* alertView = [TYAlertView alertViewWithTitle:@"修改" message:@"请输入新的信息 "];

    [alertView addAction:[TYAlertAction actionWithTitle:@"取消" style:TYAlertActionStyleCancle handler:^(TYAlertAction* action) {
                   NSLog(@"%@", action.title);
               }]];

    // 弱引用alertView 否则 会循环引用
    __typeof(alertView) __weak weakAlertView = alertView;
    [alertView addAction:[TYAlertAction actionWithTitle:@"确定" style:TYAlertActionStyleDestructive handler:^(TYAlertAction* action) {

                   NSLog(@"%@", action.title);
                   for (UITextField* textField in weakAlertView.textFieldArray) {
                       NSLog(@"%@", textField.text);
                       switch (sender.tag) {
                       case 0:
                           [self.userNameBtn setTitle:textField.text forState:UIControlStateNormal];
                           [[NSUserDefaults standardUserDefaults] setObject:textField.text forKey:KsmallName];

                           break;
                       case 1:
                           [self.identifierBtn setTitle:textField.text forState:UIControlStateNormal];
                           [[NSUserDefaults standardUserDefaults] setObject:textField.text forKey:Kidetifier];
                           break;
                       case 2:
                           [self.phoneNumButton setTitle:textField.text forState:UIControlStateNormal];
                           [[NSUserDefaults standardUserDefaults] setObject:textField.text forKey:KUserName];
                           break;

                       default:
                           break;
                       }
                   }

               }]];

    [alertView addTextFieldWithConfigurationHandler:^(UITextField* textField) {
        textField.placeholder = @"请输入修改后的信息";
    }];
    //    [alertView addTextFieldWithConfigurationHandler:^(UITextField *textField) {
    //        textField.placeholder = @"请输入密码";
    //    }];

    // first way to show
    TYAlertController* alertController = [TYAlertController alertControllerWithAlertView:alertView preferredStyle:TYAlertControllerStyleAlert];

    [alertController setViewWillShowHandler:^(UIView* alertView) {
        NSLog(@"ViewWillShow");
    }];

    [alertController setViewDidShowHandler:^(UIView* alertView) {
        NSLog(@"ViewDidShow");
    }];

    [alertController setViewWillHideHandler:^(UIView* alertView) {
        NSLog(@"ViewWillHide");
    }];

    [alertController setViewDidHideHandler:^(UIView* alertView) {
        NSLog(@"ViewDidHide");
    }];

    [alertController setDismissComplete:^{
        NSLog(@"DismissComplete");
    }];

    //alertController.alertViewOriginY = 60;
    [self presentViewController:alertController animated:YES completion:nil];

    // second way ,use UIView Category
    //[alertView showInController:self preferredStyle:TYAlertControllerStyleAlert];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 实现UIImagePickerController的代理方法
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString*, id>*)info
{
    //获取裁剪后的图像
//    UIImage* image = info[UIImagePickerControllerEditedImage];
    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    //将照片存到媒体库
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);

    self.iconImageView.image = image;

    //将照片存到沙盒
    [self saveImage:image];

    [picker dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - 照片存到本地后的回调
- (void)image:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo
{
    if (!error) {
        NSLog(@"存储成功");
    }
    else {
        NSLog(@"存储失败：%@", error);
    }
}

#pragma mark - 保存图片
- (void)saveImage:(UIImage*)currentImage
{
    //设置照片的品质
    NSData* imageData = UIImageJPEGRepresentation(currentImage, 0.5);

    NSLog(@"%@", NSHomeDirectory());
    // 获取沙盒目录
//    NSString* filePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/currentImage.png"];
    NSString *filePath = [NSHomeDirectory() stringByAppendingPathComponent:@"headImage.png"];
    [[NSUserDefaults standardUserDefaults]setObject:filePath forKey:KheadImage];

    // 将图片写入文件
    [imageData writeToFile:filePath atomically:NO];
}
//#pragma mark - 取消操作时调用
//- (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker
//{
//    [picker dismissViewControllerAnimated:YES completion:^{
//    }];
//}

#pragma mark - 打开相机
- (void)ClickControlAction
{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera; //设置类型为相机
        UIImagePickerController* picker = [[UIImagePickerController alloc] init]; //初始化
        picker.delegate = self; //设置代理
        picker.allowsEditing = YES; //设置照片可编辑
        picker.sourceType = sourceType;
        //设置是否显示相机控制按钮 默认为YES
        picker.showsCameraControls = YES;

        //        //创建叠加层(例如添加的相框)
        //        UIView *overLayView=[[UIView alloc]initWithFrame:CGRectMake(0, 120, 320, 254)];
        //        //取景器的背景图片，该图片中间挖掉了一块变成透明，用来显示摄像头获取的图片；
        //        UIImage *overLayImag=[UIImage imageNamed:@"zhaoxiangdingwei.png"];
        //        UIImageView *bgImageView=[[UIImageView alloc]initWithImage:overLayImag];
        //        [overLayView addSubview:bgImageView];
        //        picker.cameraOverlayView=overLayView;

        //选择前置摄像头或后置摄像头
        picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
        [self presentViewController:picker animated:YES completion:^{
        }];
    }
    else {
        NSLog(@"该设备无相机");
    }
}
#pragma mark - 从相册获取图片
//- (IBAction)photoFromAlbum:(id)sender {
//    //首先需要判断资源是否可用
//    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
//
//        UIImagePickerController *pickerImage = [[UIImagePickerController alloc] init];
//
//        pickerImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//        //获得相机模式下支持的媒体类型
//        //        pickerImage.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:pickerImage.sourceType];
//        pickerImage.delegate = self;
//        //设置允许编辑
//        pickerImage.allowsEditing = YES;
//
//        [self presentViewController:pickerImage animated:YES completion:^{
//        }];
//    }
//}
#pragma mark - 从相册选择图片后操作
//- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
//
//    //NSLog(@"%@",info);
//
//    //获取源图像（未经裁剪）
//    //    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
//
//    //获取裁剪后的图像
//    UIImage *image = info[UIImagePickerControllerEditedImage];
//
//    //将照片存到媒体库
//    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
//
//    self.photoImage.image = image;
//
//    //将照片存到沙盒
//    [self saveImage:image];
//
//    [picker dismissViewControllerAnimated:YES completion:^{
//    }];
//}
@end
